package com.xinxin.intelligenceexam.activity;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Process;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.orhanobut.logger.Logger;
import com.xinxin.intelligenceexam.R;
import com.xinxin.intelligenceexam.contract.MainContract;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


public class MainActivity extends AppCompatActivity implements MainContract.View {
    @BindView(R.id.btn_exam)
    Button mBtnExam;
    @BindView(R.id.btn_test)
    Button mBtnTest;
    private long exitTime = 0;
    private Context mContext;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mContext = this;
        ButterKnife.bind(this);
    }

    @Override
    public void onBackPressed() {
        //2秒内连续点击退出应用
        if (System.currentTimeMillis() - exitTime > 2000) {
            Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT).show();
            exitTime = System.currentTimeMillis();
        } else {
            finish();
            System.exit(0);
            Process.killProcess(Process.myPid());
        }
    }

    @OnClick({R.id.btn_exam, R.id.btn_test})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_exam:
                new AlertDialog.Builder(mContext).setMessage("进入考试界面后请不要退出,做完所有试题后提交才会保存测试结果，否则成绩无效").setPositiveButton("开始考试", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        startActivity(new Intent(mContext, ExamActivity.class));
                    }
                }).setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Logger.d("取消测试");
                    }
                }).show();
                break;
            case R.id.btn_test:
                break;
        }
    }
}
